# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    def isEvenOddTree(self, root: TreeNode) -> bool:
        queue = []
        layer = 0
        if root:
            queue.append(root)
        while queue:
            mod = layer % 2
            pre = 0 if mod == 0 else 10**6 + 1
            for _ in range(len(queue)):
                node = queue.pop(0)
                if mod == 0:
                    if node.val % 2 == 0 or pre >= node.val:
                        return False
                else:
                    if node.val % 2 == 1 or pre <= node.val:
                        return False
                pre = node.val
                if node.left:
                    queue.append(node.left)
                if node.right:
                    queue.append(node.right)
            layer += 1
        return True
